import pagination from '@/views/pagination'  //分页组件 
import qiniu from '@/views/qiniu/upload'
import agentHttp from '@/utils/agentHttp.js' 
import {debounce,setEndDateTime} from '@/utils/index.js'
export default {
  name: 'hotBrands',
  created(){
        this.seachData();
  },
  components:{qiniu,pagination},
  data() {
  	return {
        form:[{
          name:""
        }],
        searchForm:{
          name1:""
        },
    		tableData: [{  }],
        //弹窗状态值
        isAdd:false,
        dialogFormVisible: false,
        dialogFormVisible1:false,
        formLabelWidth:'120px',
        //汽车及价格信息
        dialogForm:{
           funderId:"",
           signatory:[] ,
           spvSignNumber:0,
           zjfSignNumber:0,
           jxsSignNumber:0,
           lscSignNumber:0,
           parameters:[],
           apiType:"" 
        },
        options: [{
          value: '品牌1',
          label: '品牌1'
        }],
        isAdd_add:true,
        funderUserList:[],
        resetFormStatus:false
  	}
  },
  methods: {  
    
    seachData(){
      if(!this.resetFormStatus){
        var params=this.searchForm||{}; 
        params.page=this.tableData.page||1;
        params.rows=this.tableData.rows||10;
        agentHttp.post('adminApi/admin/contract_template_info/queryAll',params ).then((data)=>{ 
              this.tableData = data;  
              //获取资金方
              agentHttp.get('adminApi/token/get_funder_user').then((data)=>{ 
                  this.funderUserList = data.data
              });
        })
      }
    },
    addRows(index){ 
      this.dialogForm.parametersVO.push("");
    },
    delRows(index){
      
      if ( this.dialogForm.parametersVO.length > 0) { 
        if ( this.dialogForm.parametersVO.length == 1){
             this.$message({  type: 'warning', message: '请至少保留一条数据..'  });
             return;
        }
        this.dialogForm.parametersVO.splice(index,1)
      }
    },
    parametersDialog(){ 
      this.dialogFormVisible1=true;
      //如果数据库没有，初始化一个
      if(this.dialogForm.parametersVO == null || this.dialogForm.parametersVO.length <= 0){
         this.dialogForm.parametersVO = [];
         this.dialogForm.parametersVO.push("");
      }
    },
    submitSearchForm(formName){
      console.log(formName);
    },
    //重置
    resetSearchForm(formName) {
      this.resetFormStatus=true;
      this.tableData.page=1;
      this.tableData.rows=10;
      this.$refs[formName].resetFields();
      this.$nextTick(_ =>{
        this.resetFormStatus=false;
        this.seachData();
      })
    },
    /*表格操作按钮*/
    //查看
    handleSee(index, row){ 
      //获取当前选择的行数据
      this.getDiglogFormData(row);
      this.isAdd=false;
      this.dialogFormVisible=true;
      
    }
    ,pushCheckValue(row){
        if(row.spvInclued){
          this.dialogForm.signatory.push("spvInclued");
        }
        if(row.lscInclued){
          this.dialogForm.signatory.push("lscInclued");
        }
        if(row.dealerInclued){
          this.dialogForm.signatory.push("dealerInclued");
        }
        if(row.funderInclued){
          this.dialogForm.signatory.push("funderInclued");
        }
        if(row.lscSpvInclued){
          this.dialogForm.signatory.push("lscSpvInclued");
        }
        if(row.lscSpvLoaneeInclued){
          this.dialogForm.signatory.push("lscSpvLoaneeInclued");
        }
    },
    //编辑/审核
    handleEdit(index, row, add_edit) { 
      this.isAdd=true; 
      this.dialogFormVisible=true;
      //修改
      if(add_edit){
        //获取当前选择的行数据
        this.getDiglogFormData(row);
        var url="update"
        this.isAdd_add=false
      }else{
        this.initData();
        var url="add"
        this.isAdd_add=true
      }

    },
    getDiglogFormData(row){ 
      this.dialogForm = row; 
      this.dialogForm.signatory = [];
      this.pushCheckValue( row);
    },
    handleDelete(index, row){
      var str = "确认启用该条数据吗?";
      if(row.enable){
          str = '确认停用该条数据吗?';
      }
      this.$confirm(str, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
           var params = {
              id:row.id,
              enable:row.enable
           }  
           agentHttp.put('adminApi/admin/contract_template_info/enabled_or_disable',params).then((data)=>{ 
                this.$message({  type: 'success', message: data.data  });
                this.seachData();
           });
           
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '取消当前操作...'
          });          
        });
    }, 
    initData(){
      this.dialogForm = {
           funderId:"",
           signatory:[] ,
           spvSignNumber:0,
           zjfSignNumber:0,
           jxsSignNumber:0,
           lscSignNumber:0,
           parameters:[],
           parametersVO:[],
           apiType:"" 
      }
    },
    //提交按钮
    submitDialogForm(){ 

        if( this.dialogForm.signatory.length <= 0 ){
            this.seachData();
            this.$message({  type: 'warning', message: '请至少选中一个签署方..'  });
            return;   
        } 
        this.dialogForm.parameters = JSON.stringify( this.dialogForm.parametersVO);
        delete this.dialogForm.parametersVO;
        //添加
        if(this.isAdd_add){
           agentHttp.postJson('adminApi/admin/contract_template_info/post_validated',this.dialogForm).then((data)=>{ 
                this.$message({  type: 'info', message: data.data  });
                this.seachData();
                this.dialogFormVisible = false;
           });

        } 
        //修改
        else {
           agentHttp.putJson('adminApi/admin/contract_template_info/put_validated',this.dialogForm).then((data)=>{ 
                this.$message({  type: 'info', message: data.data  });
                this.seachData();
                this.dialogFormVisible = false;
           });

        } 
    } 

  }



}